<template>
    <h2>新增</h2>
    <table border="1">
        <tr>
            <td>代金券标题</td>
            <td>
                <input type="text" v-model="info.Vocher_Title">
            </td>
        </tr>
        <tr>
            <td>代金券颜色</td>
            <td>
                <input type="text" v-model="info.Vocher_Color">
            </td>
        </tr>
        <tr>
            <td>代金券库存</td>
            <td>
                <input type="number" v-model="info.Voucher_Num">
            </td>
        </tr>
        <tr>
            <td>每人限领</td>
            <td>
                <input type="number" v-model="info.Voucher_Limited">
            </td>
        </tr>
        <tr>
            <td>代金券开始有效期</td>
            <td>
                <input type="date" v-model="info.Voucher_SDate">
            </td>
        </tr>
        <tr>
            <td>代金券结束有效期</td>
            <td>
                <input type="date" v-model="info.Voucher_EDate">
            </td>
        </tr>
        <tr>
            <td>代金券金额</td>
            <td>
                <input type="number" v-model="info.Voucher_Money">
            </td>
        </tr>
        <tr>
            <td>代金券使用须知</td>
            <td>
                <input type="text" v-model="info.Voucher_Precautions">
            </td>
        </tr>
        <tr>
            <td>客服电话</td>
            <td>
                <input type="text" v-model="info.Voucher_Phone">
            </td>
        </tr>
        <tr>
            <td>门店</td>
            <td>
                <select v-model="info.ShopId">
                    <option :value="0">--请选择--</option>
                    <option v-for="item in Shops" :value="item.ShopId">{{ item.ShopName }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="保存" @click="SaveData">
            </td>
        </tr>
        
    </table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';

onMounted(()=>{
    GetShop();
})

const GetShop=()=>{

    axios.get('https://localhost:7153/api/Voucher/GetShops')
    .then(res=>{
        Shops.value=res.data
    })


}

const info=ref({
    Vocher_Title:"",
    Vocher_Color:"",
    Voucher_Num:"",
    Voucher_Limited:"",
    Voucher_Money:"",
    Voucher_SDate:"",
    Voucher_EDate:"",
    Voucher_Precautions:"",
    Voucher_Phone:"",
    ShopId:0

})

const SaveData=()=>{

    axios.post('https://localhost:7153/api/Voucher/AddVoucher',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("已经存在");
        }
        else if(res.data>0){
            alert("添加成功");
        }
        else{
            alert("添加失败");
        }
    })


}


const Shops=ref([{
    ShopId:0,
    ShopName:""

}])






</script>